package erupt_simultaneously;

import java.util.concurrent.CountDownLatch;

/**
 * @Auther Jun jie Yi
 * @Date 14:35 2021/7/25
 */
public class WaitThreadDone {
    public static void main(String[] args) throws InterruptedException {
        final CountDownLatch latch = new CountDownLatch(1);
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("thread "+Thread.currentThread().getName()+" start to run.");
                    Thread.sleep(2000);
                    System.out.println("thread " + Thread.currentThread().getName() + " done.");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    latch.countDown();
                }
            }
        });
        System.out.println("main start to run.");
        t1.start();
        latch.await();
        System.out.println("main done.");
    }
}
